package com.adv.ems.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.adv.ems.db.mapper.EnergyDataCumulateReportYearMapper;
import com.adv.ems.db.entity.EnergyDataCumulateReportYearDO;
import com.adv.ems.manager.EnergyDataCumulateReportYearManager;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class EnergyDataCumulateReportYearManagerImpl extends ServiceImpl<EnergyDataCumulateReportYearMapper, EnergyDataCumulateReportYearDO> implements EnergyDataCumulateReportYearManager {
    @Override
    public void deleteByPointColDate(Long pointId, Date year) {
        LambdaUpdateWrapper<EnergyDataCumulateReportYearDO> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EnergyDataCumulateReportYearDO::getCollectPointId, pointId);
        wrapper.eq(EnergyDataCumulateReportYearDO::getColDate, year);
        remove(wrapper);
    }

    @Override
    public void insertData(EnergyDataCumulateReportYearDO reportYear) {
        save(reportYear);
    }

    @Override
    public List<EnergyDataCumulateReportYearDO> selectData(Date startDate, Date endDate, List<Long> pointIds) {
        LambdaQueryWrapper<EnergyDataCumulateReportYearDO> wrapper = new LambdaQueryWrapper<>();
        if (CollectionUtils.isEmpty(pointIds)) {
            return new ArrayList<>();
        }
        wrapper.in(EnergyDataCumulateReportYearDO::getCollectPointId, pointIds);
        wrapper.ge(EnergyDataCumulateReportYearDO::getColDate, startDate);
        wrapper.le(EnergyDataCumulateReportYearDO::getColDate, endDate);
        return list(wrapper);
    }
}
